package com.yf.aclient.notification;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.yf.aclient.MyClientActivity;



public class MyNotificationMgr {
	 private  NotificationManager mNotificationManager;
	 private int drawableId;
	 private String infoText;
	 private boolean ifScrolling;
	 private Context context;
	 private int notificationId;
	 private String title;
	 /***
	  * 
	  * @param view 显示面板的引用
	  * @param drawableId  显示图标的id
	  * @param title  通知的标题
	  * @param infoText  通知的内容
	  * @param ifScrolling  是否SCROLLING
	  * @param notificationId  通知唯一id.
	  */
	 public MyNotificationMgr(NotificationManager mNotificationManager,Context context,int drawableId,String title,String infoText,boolean ifScrolling,int notificationId){

		 this.context=context;
		 this.drawableId=drawableId;
		 this.infoText=infoText;
		 this.ifScrolling=ifScrolling;
		 this.notificationId=notificationId;
		 this.mNotificationManager=mNotificationManager;
		 this.title=title;
		 notificate();
	 }
	 
	    private void notificate() {
	        // In this sample, we'll use the same text for the ticker and the expanded notification
	        CharSequence text = infoText;

	        // choose the ticker text
	        String tickerText = ifScrolling ? infoText: null;

	        // Set the icon, scrolling text and timestamp
	        Notification notification = new Notification(drawableId, tickerText,
	                System.currentTimeMillis());

	        // Set the info for the views that show in the notification panel.
	        notification.setLatestEventInfo(context, title,
	                       text, makeMoodIntent(drawableId));

	        // Send the notification.
	        // We use a layout id because it is a unique number.  We use it later to cancel.
	        mNotificationManager.notify(notificationId, notification);
	    }
	    private PendingIntent makeMoodIntent(int moodId) {
	        // The PendingIntent to launch our activity if the user selects this
	        // notification.  Note the use of FLAG_UPDATE_CURRENT so that if there
	        // is already an active matching pending intent, we will update its
	        // extras to be the ones passed in here.
	        PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
	                new Intent(context, MyClientActivity.class)
	                        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
	                        .putExtra("moodimg", moodId),
	                PendingIntent.FLAG_UPDATE_CURRENT);
	        return contentIntent;
	    }
}
